/*-----------------------------------------------------
 * 权限子系统-系统序列模块
 * ---------------------------------------------------*/
jx.ready(function () {
    //定义变量
    var api = {
        grid: '/auth/sequence/grid',
        create: '/auth/sequence/create',
        edit: '/auth/sequence/edit',
        delete: '/auth/sequence/delete',
        details: '/auth/sequence/details',
        export: '/auth/sequence/export'
    };
    var $grid = $('#grid'), $gridform = $('#gridform');
    var gridInstance;
    var dialogWidth = $grid.data('dialogWidth'), dialogHeight = $grid.data('dialogHeight');
    var createTitle = '新增系统序列', editTitle = '修改系统序列', detailsTitle = '查看系统序列';
    var gridUrl = jx.apiUrl(api.grid), createUrl = jx.apiUrl(api.create),
        editUrl = jx.apiUrl(api.edit), deleteUrl = jx.apiUrl(api.delete),
        detailsUrl = jx.apiUrl(api.details), exportUrl = jx.apiUrl(api.export);

    //初始化表格
    var initGrid = function () {
        gridInstance = $grid.jxgrid({
            url: gridUrl,
            onDblClickRow: function (index, row) {
                detailsData(row);
            },
            onRowContextMenu: function (e, index, row) {
                jx.auth.gridContextMenuHandle(gridInstance, e, index, row)
            },
            onLoadSuccess: function () {
                jx.auth.showGridContextMenu(gridInstance, '#gridcmenu');
            }
        });
    };

    //初始化事件
    var initEvent = function () {
        $('#btn-create').click(function () {
            createData();
        });
        $('#btn-edit,#btn-cmedit').click(function () {
            editData();
        });
        $('#btn-delete,#btn-cmdelete').click(function () {
            deleteData();
        });
        $('#btn-export').click(function () {
            exportData();
        });
    };

    //新建数据
    var createData = function () {
        jx.dialog({
            title: createTitle,
            url: createUrl,
            width: dialogWidth,
            height: dialogHeight
        });
    };

    //编辑数据
    var editData = function () {
        jx.auth.editData(gridInstance, {
            title: editTitle,
            url: editUrl,
            width: dialogWidth,
            height: dialogHeight
        });
    };

    //删除数据
    var deleteData = function () {
        jx.auth.deleteData(gridInstance, {
            url: deleteUrl
        });
    };

    //查看数据
    var detailsData = function (row) {
        jx.auth.detailsData(gridInstance, row, {
            title: detailsTitle,
            url: detailsUrl,
            width: '50%'
        });
    };

    //导出数据
    var exportData = function () {
        jx.auth.exportData(exportUrl, jx.serialize($gridform));
    };

    //定义表格列格式化函数

    //对外接口
    //重新加载表格数据
    window.reloadGridData = function () {
        gridInstance.reloadGridData();
    };

    //初始化
    initGrid();
    initEvent();
});